package com.ls.fw.mongo.dao;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.bson.Document;
import org.bson.conversions.Bson;

import com.ls.fw.mongo.bean.IndexBean;
import com.ls.fw.mongo.helper.MongoDbHelper;
import com.mongodb.client.FindIterable;
import com.mongodb.client.ListIndexesIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;

public interface MongoDbClient {
	
	public static final String _ID = MongoDbHelper._ID;
	
	void close();

	void dropCollection(String dbName, String collName);

	long updateById(MongoCollection<Document> coll, String id, Document newdoc);

	long deleteById(MongoCollection<Document> coll, String... id);

	MongoCursor<Document> findByPage(MongoCollection<Document> coll, Bson filter, int pageNo, int pageSize);

	MongoCursor<Document> find(MongoCollection<Document> coll, Bson filter);

	int getCount(MongoCollection<Document> coll);

	Document findById(MongoCollection<Document> coll, String id);

	void dropDB(String dbName);

	MongoIterable<String> getAllDBNames();

	List<String> getAllCollections(String dbName);

	MongoCollection<Document> getCollection(String dbName, String collName);

	MongoDatabase getDB(String dbName);

	void insert(String dbName,String table,Map<String,Object> map) throws Exception;
	
	void insert(String dbName,String table,List<Map<String,Object>> map) throws Exception;

	void createIndex(String dbName,String table,Set<String> index);

	MongoCursor<Document> findByPage(MongoCollection<Document> coll, Bson filter, int pageNo, int pageSize,
			String orderField, int order);

	long save(MongoCollection<Document> coll, String id, Document newdoc);

	MongoCursor<Document> findByPage(MongoCollection<Document> coll, Bson filter, int pageNo, int pageSize, Bson sort);

	long inc(MongoCollection<Document> coll, String id, Document newdoc);

	boolean exist(MongoCollection<Document> coll, String id);

	long save(MongoCollection<Document> coll, String id, Map<String, Object> map) throws Exception;

	FindIterable<Document> findByIds(MongoCollection<Document> coll, String[] id);

	ListIndexesIterable<Document> findIndex(String dbName, String table);

	void dropIndex(String dbName, String table, IndexBean... index);

	void createIndex(String dbName, String table, IndexBean... index);
}
